package cn.zhaoguang.usedcar.main.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Author zhaoguang
 * @Date 2021/3/8 2:21
 */
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {

    @Bean
    public Docket defaultApi() {
        //在请求头中添加Token参数
//        ParameterBuilder parameterBuilder = new ParameterBuilder();
//        List<Parameter> parameters = new ArrayList<>();
//        parameterBuilder.name("Authorization").description("Token令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
//        parameters.add(parameterBuilder.build());
        //配置Swagger
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("接口文档")
                        .description("简单优雅的RESTful API")
                        .termsOfServiceUrl("http://localhost:8090/automobile")
                        .version("1.0")
                        .build())
                .select()
                //指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("cn.zhaoguang.usedcar.main.controller"))
                .paths(PathSelectors.any())
//                .build().globalOperationParameters(parameters);
                .build();
        return docket;

    }
}
